package org.dfrt.own.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author zhang
 * ClassName: CharsetEncoding
 * Description: 设置中文编码的过滤器
 * date: 2023/10/3 16:28
 * @since JDK 8
 */

public class CharsetEncoding implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("utf-8");
        servletResponse.setCharacterEncoding("utf-8");
        /**
         * 一个过滤器称为过滤器 多个过滤器称为过滤器链
         *
         * 移交给下一个过滤器
         *
         */
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
